package com.cxhc.app.api;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cxhc.system.domain.app.CmInfom;
import com.cxhc.system.service.app.ICmInfomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.utils.poi.ExcelUtil;
import com.cxhc.common.core.page.TableDataInfo;

/**
 * 信息Controller
 * 
 * @author Dhq
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/api/infom")
public class ApiCmInfom extends BaseController
{
    @Autowired
    private ICmInfomService cmInfomService;

    /**
     * 查询信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmInfom cmInfom)
    {
        startPage();
        List<CmInfom> list = cmInfomService.selectCmInfomList(cmInfom);
        return getDataTable(list);
    }

    /**
     * 导出信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmInfom cmInfom)
    {
        List<CmInfom> list = cmInfomService.selectCmInfomList(cmInfom);
        ExcelUtil<CmInfom> util = new ExcelUtil<CmInfom>(CmInfom.class);
        util.exportExcel(response, list, "信息数据");
    }

    /**
     * 获取信息详细信息
     */
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmInfomService.selectCmInfomById(id));
    }

    /**
     * 新增信息
     */
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody CmInfom cmInfom)
    {
        return toAjax(cmInfomService.insertCmInfom(cmInfom));
    }

    /**
     * 修改信息
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody CmInfom cmInfom)
    {
        return toAjax(cmInfomService.updateCmInfom(cmInfom));
    }

    /**
     * 删除信息
     */
	@DeleteMapping("/delete/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(cmInfomService.deleteCmInfomById(id));
    }
}
